package com.zhny.aiot.infrared.ray.plugin.factory.imp;

import com.zhny.aiot.infrared.ray.plugin.factory.IinfraredRayFactory;
import com.zhny.aiot.infrared.ray.plugin.model.InfraredRayStoreEntry;
import io.netty.buffer.ByteBuf;

public class PassInOutFactory implements IinfraredRayFactory {
    @Override
    public InfraredRayStoreEntry onDecode(ByteBuf buf) {
        InfraredRayStoreEntry storeEntry = new InfraredRayStoreEntry();
        buf.skipBytes(6);
        int flag = buf.readByte();
        int inCount = buf.readUnsignedShort();
        int outCount = buf.readUnsignedShort();
        int leaveCount = buf.readUnsignedShort();
        leaveCount = outCount > inCount?0:leaveCount;
        storeEntry.setInCount(inCount);
        storeEntry.setOutCount(outCount);
        storeEntry.setLeaveCount(leaveCount);
        return storeEntry;
    }
}
